﻿import QtQuick 2.12
import QtQuick.Layouts 1.12
import QtQuick.Window 2.12
import "../components"

Window {

    title: "打印报告"
    id: root
    modality: Qt.WindowModal
    flags: Qt.Window | Qt.WindowTitleHint |Qt.WindowSystemMenuHint | Qt.WindowCloseButtonHint


    height: 1000*dp
    width:  1280*dp

    minimumHeight: 1000*dp
    maximumHeight: 1000*dp
    minimumWidth: 1280*dp
    maximumWidth: 1280*dp
    color: "#EAEAEA"

    property string localPrinterName: "本地 (Word, Excel, Csv)"


    Rectangle{
        color: "#4499FA"
        x: 98*dp; y: 18*dp
        height: 939*dp
        width: 724*dp
        Image{
            id: image_preview
            x: 2*dp; y: 2*dp
            height: 935*dp
            width: 720*dp
//            source: "qrc:/picture/printTemplate.png"
            source: "image://printPreviewImage"
        }
        Text{
            y: parent.height+4*dp
            text: "* 图片仅供参考，最终结果请以实物为准"
            font.pixelSize: config.fontsize
            opacity: 0.8
        }
    }

    onVisibleChanged: {
        if(visible){
            CPrinter.refreshPreview(dp)
            image_preview.source = "image://printPreviewImage/" + Math.random()
            let model = CPrinter.getPrinterList()
            model.splice(0, 0, localPrinterName)
            combo_printer.model = model
        }
    }
    Item{
        x: 900*dp; y: 40*dp
        width: parent.width - x - 100*dp
        Column{
            spacing: 20*dp
            Item{
                height: 40*dp; width: 40*dp
                Text{
                    text: "打印设置"
                    font.bold: true
                    font.pixelSize: config.fontsize + 4*dp
                }
            }
            CustomComboBox{
                id: combo_printer
                title: "打印机"
                editWidth: 220*dp
                model: ["OneNote (DeskTop)", "HP-7200"]
            }CustomComboBox{
                title: "纸张大小"
                editWidth: 220*dp
                model: ["A4", "B5"]
            }
        }
        Item{
            height: 40*dp; width: parent.width
            y: 250*dp
            PushButton{
                title: "取消"
                defaultMode2: true
                x: parent.width/2-130*dp
                onReleased: {
                    root.close()
                }
            }

            PushButton{
                title: "打印"
                defaultMode1: true
                x: parent.width/2+10*dp
                onReleased: {
                    if(combo_printer.getText() === localPrinterName){
                        CReport.exportReport()
                    }else{
                        CPrinter.print(combo_printer.getText())
                    }
                }
            }
        }
    }


}
